<?php

class SignupForm extends AppModel{
	var $name = 'SignUpForm';
	var $useTable = false;
	
	var $validate = array(
		'password' => array(
			'alphaNumeric' => array(
				'rule' => 'alphaNumeric',
				'required' => true,
				'allowEmpty' => false,
				'message' => Messages::password_repeat_must_be_alphabet_or_numeric
			),
			'minLength' => array(
				'rule' => array('minLength', 6),
				'message' => Messages::password_length_must_be_longer_than_6_characters
			)
		),
		'email' => array(
			'email' => array(
				'rule' => 'email',
				'required' => true,
				'message' => Messages::invalid_email_address
			),
			'isUnique' => array(
				'rule' => 'isUniqueEmail',
				'message' => Messages::email_has_been_existed
			)
		),
		'first_name' => array(
			'maxlength' => array(
				'rule' => array('maxLength',45),
				'message' => Messages::firstname_max_length_must_be_less_than_45_characters
			),
			'minlength' => array(
				'rule' => 'notEmpty',
				'required' => true,
				'message' => Messages::you_must_enter_your_username
			),
			'specialCharacters' => array(
				'rule' => 'specialCharacters',
				'message' => Messages::username_must_contain_only_letters_and_numbers
			)
		),
		'last_name' => array(
			'maxlength' => array(
				'rule' => array('maxLength', 45),
				'message' => Messages::lastname_must_be_less_than_45_characters
			),
			'specialCharacters' => array(
				'rule' => 'specialCharacters',
				'message' => Messages::username_must_contain_only_letters_and_numbers
			)
		),
		'term' => array(
			'rule' => array('equalTo', '1'),
			'required' => true,
			'message' => Messages::term_of_service
		)
		
	);
	
	function isUniqueEmail($email){
		App::import('model','User');
		$user = new User();
		$result = $user->findByEmail($email);
		if($result){
			return FALSE;
		}else{
			return TRUE;
		}
	}
	
	function isUniqueUsername($userName){
		App::import('model','Profile');
		$profile = new Profile();
		$result = $profile->findByName($userName);
		if($result){
			return FALSE;
		}else{
			return TRUE;
		}
	}

	function alphaNumericDashUnderscoreSpace($check) {
      // $data array is passed using the form field name as the key
      // have to extract the value to make the function generic
      $value = array_shift($check);
      return preg_match('|^[0-9a-zA-Z_ -]*$|', $value);
    }
	
}
?>
